<?php

/*

Global Forums (global_forums.php)

*/

$interactive = 1;
$page_title = "Global OPG Forums";
$rank_check = 3;
include "header.inc.php";

$topics = mysql_query("SELECT * FROM global_subjects ORDER BY last_post_at DESC LIMIT 25");

while ($array = mysql_fetch_array($topics))
{
	if (($rank >= 4) AND ($array[reports] >= 5)) { $delete = " <a href='global_forum_delete.pro.php?game=$game&topic=$array[id]&order=$order&goto=$id' onClick=\"if ( !confirm ('Are you sure you want to delete this post?') ) { return false; }\"><font size=-1>(Delete!)</font></a>"; }

	$cellcolor = alternate($cellcolor,"$reallyLight","#FFFFFF");
	$get_author = fetch("SELECT id,username,display_name,premium,display_prem,game FROM members2 WHERE id = '$array[author]'");
	$get_responder = fetch("SELECT id,username,display_name,premium,display_prem,game FROM members2 WHERE id = '$array[last_post_by]'");
	$lastpost_string = date("M j @ g:i",$array[last_post_at]);

	if (($get_author[premium] == 1) AND ($get_author[display_prem]))
	{
		$get_author[display_name] = $get_author[display_prem];
	}
	if (($get_responder[premium] == 1) AND ($get_responder[display_prem]))
	{
		$get_responder[display_name] = $get_responder[display_prem];
	}

	$numReplies2 = fetch("SELECT count(id) AS id FROM global_replies WHERE thread = '$array[id]'");

	if ($numReplies2[id] < 10) { $numReplies = "$numReplies2[id] Replies"; }
	if ($numReplies2[id] >= 10) { $numReplies = "<font color=#CC0099><b>$numReplies2[id] Replies</b></font>"; }
	if ($numReplies2[id] > 25) { $numReplies = "<font color=#009900><b>$numReplies2[id] Replies</b></font>"; }
	if ($numReplies2[id] > 25) { $numReplies = "<font color=#FF0000><b>$numReplies2[id] Replies</b></font>"; }

	$topicID = $array[id];

	if ($numReplies2[id] > 25) { $pages[$topicID] = ceil($numReplies2[id] / 25); }
	if ($pages[$topicID] > 1)
	{
		for ($p = 1; $p <= $pages[$topicID]; $p++)
		{
			if ($p == 1) { $list_pages[$topicID] = "<br><font size=-1>Pages ["; }
			if (($p == 4) AND ($p != "$pages[$topicID]")) { $p = $pages[$topicID] - 1; $list_pages[$topicID] .= "..."; }
			if ($p < $pages[$topicID]) { $list_pages[$topicID] .= "<a href=$base_url/global_topic.php?game=$game&id=$array[id]&page=$p>$p</a>, "; }
			if ($p == $pages[$topicID]) { $list_pages[$topicID] .= "<a href=$base_url/global_topic.php?game=$game&id=$array[id]&page=$p>$p</a>]</font>"; }
		}
	}

	$array[subject] = smilies($array[subject]);

	$topic_list .= "
	<tr bgcolor=$cellcolor onmouseover=\"this.style.background='$middleBG';\" onmouseout=\"this.style.background='$cellcolor';\" width=100%>

<td><p><a href=$base_url/global_view_topic.php?game=$game&id=$array[id]>$array[subject]</a>$delete$list_pages[$topicID]</p></td>

<td width=115><p align=center><a href=$base_url/global_profile.php?user=$get_author[id]&game=$game>$get_author[display_name] - Game #$get_author[game]</a></p></td>

<td width=100><p align=center>$numReplies</p></td>

<td width=115><p align=center><font size=-1>Last post by:<br><a href=global_profile.php?user=$get_responder[id]&game=$game>$get_responder[display_name] - Game #$get_responder[game]</a> at:<Br>$lastpost_string</font></p></td></tr>";

}

print "<p><b>Welcome to the Global OPG Forums. Failure to obey the <a href=rules.php?game=$game>rules</a> may result in suspension of your account. <font color=red>Remember to Keep it clean, anything over PG will be deleted.</font></b></p>";

ECHO <<<END

<center>
<form action=global_add_topic.php?game=$game&add_to=$id method=post>
<input type=submit value="Add Topic">
</form>
</center>

<CENTER><BR> <TABLE BGCOLOR="$tableOutline" CELLSPACING=1 CELLPADDING=0 WIDTH=95%>

<tr bgcolor=$topAndBottomBG width=100%><td><p><font color=$topAndBottomText><b>Topic</b></font></p></td><td width=115><p align=center><font color=$topAndBottomText><b>Author</b></font></p></td><td width=100><p align=center><font color=$topAndBottomText><b>Replies</b></font></p></td><td width=115><p align=center><font color=$topAndBottomText><b>Last Action</b></font></p></td></tr>$topic_list</table><br>

END;

?>